package com.zb.frame.base.model;

import java.util.HashMap;

/**
 * <p>
 *  http标准响应对象，统一进行交互
 * </p>
 *
 * @author bangZZ
 * @since 2020-06-04
 */
public class R extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    public R() {
        this.put("code", 200);
        this.put("msg", "success");
    }

    public static R ok() {
        return new R();
    }

    public static R ok(String msg) {
        return R.ok().put("msg", msg);
    }

    public static R ok(Object data) {
        return R.ok().put("data", data);
    }

    public static R ok(String msg, Object data) {
        return R.ok().put("msg", msg).put("data", data);
    }

    public static R error() {
        return error(500, "","未知异常，请联系管理员");
    }

    public static R error(String msg) {
        return error(500,"", msg);
    }

    public static R error(Integer code, String error) {
        return error(code, error, "");
    }

    public static R error(Integer code, String error, String msg) {
        return R.ok().put("code", code).put("error", error).put("msg",msg);
    }

    @Override
    public R put(String key, Object value){
        super.put(key, value);
        return this;
    }

}
